# Process this file with `autoreconf -i` to create a 'configure' file.

#  Licensed to the Apache Software Foundation (ASF) under one
#  or more contributor license agreements.  See the NOTICE file
#  distributed with this work for additional information
#  regarding copyright ownership.  The ASF licenses this file
#  to you under the Apache License, Version 2.0 (the
#  "License"); you may not use this file except in compliance
#  with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

# Table of Contents
# 1. INITIALIZATION
# 2. SITE CONFIGURATION
# 3. CHECK FOR PROGRAMS
# 4. CHECK FOR LIBRARIES
# 5. CHECK FOR HEADERS
# 6. OUTPUT FILES
# 7. autoheader TEMPLATES

# -----------------------------------------------------------------------------
# 1. INITIALIZATION

# These first two version numbers are updated automatically on each release.
# Version number is calculated as MAJOR * 1000000 + MINOR * 1000 + MICRO
# Version string is in the form of MAJOR.MINOR.MICRO[sufix]
#
m4_define([TS_VERSION_S],[5.2.0])
m4_define([TS_VERSION_N],[5002000])

AC_INIT([Apache Traffic Server], TS_VERSION_S(), [dev@trafficserver.apache.org], [trafficserver],[http://trafficserver.apache.org])
AC_PREREQ([2.59])
AC_CONFIG_AUX_DIR([build/aux])
AC_CONFIG_SRCDIR([proxy/Main.cc])
AC_CONFIG_MACRO_DIR([build])
AM_INIT_AUTOMAKE([-Wall -Werror tar-ustar foreign no-installinfo no-installman subdir-objects 1.9.2])
AC_CONFIG_HEADERS([lib/ts/ink_autoconf.h])

# Configure with --disable-silent-rules to get verbose output. For more info, see
# http://www.gnu.org/software/automake/manual/html_node/Automake-silent_002drules-Option.html
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

# Libtool versioning uses different conventions on different
# platforms.  At least on FreeBSD, libtool uses an overly complex
# convention that attempts to solve problems that most people just
# don't have and which just causes confusion for most end users.
#
TS_VERSION_MAJOR=$((TS_VERSION_N() / 1000000 ))
TS_VERSION_MINOR=$(((TS_VERSION_N() / 1000) % 1000 ))
TS_VERSION_MICRO=$((TS_VERSION_N() % 1000 ))
TS_LIBTOOL_MAJOR=`echo $((${TS_VERSION_MAJOR} + ${TS_VERSION_MINOR}))`
TS_LIBTOOL_VERSION=$TS_LIBTOOL_MAJOR:$TS_VERSION_MICRO:$TS_VERSION_MINOR
TS_VERSION_STRING=TS_VERSION_S()
TS_VERSION_NUMBER=TS_VERSION_N()

#
# Substitute the above version numbers into the various files below.
#
AC_SUBST(TS_LIBTOOL_VERSION)
AC_SUBST(TS_VERSION_STRING)
AC_SUBST(TS_VERSION_NUMBER)
AC_SUBST(TS_VERSION_MAJOR)
AC_SUBST(TS_VERSION_MINOR)
AC_SUBST(TS_VERSION_MICRO)

dnl Hard-coded top of ink_autoconf.h:
AH_TOP([
#ifndef _ink_autoconf_h
#define _ink_autoconf_h
])

dnl Hard-coded inclusion at the tail end of ink_autoconf.h:
AH_BOTTOM([

#endif /* _ink_autoconf_h */
])

#
# Generate ./config.nice for reproducing runs of configure
#
TS_CONFIG_NICE([config.nice])

# XXX we can't just use AC_PREFIX_DEFAULT because that isn't subbed in
# by configure until it is too late.  Is that how it should be or not?
# Something seems broken here.
AC_PREFIX_DEFAULT([/usr/local/trafficserver])

# Get the layout here, so we can pass the required variables to Trafficserver
TS_ENABLE_LAYOUT(TrafficServer, [cachedir docdir])

# Reparse the configure arguments so we can override the layout.
TS_PARSE_ARGUMENTS

#
# Host detection
#
AC_CANONICAL_HOST
HOST_GUESS="$host"
AC_SUBST(HOST_GUESS)

AC_ARG_WITH([user],
  [AS_HELP_STRING([--with-user],[specify the system user [default=nobody]])],
  [
  with_user="$withval"
  ],[
  with_user="nobody"
  ]
)

default_group="`id -ng $with_user`"
AC_ARG_WITH([group],
  [AS_HELP_STRING([--with-group],[specify the system group [default=nobody]])],
  [
  with_group="$withval"
  ],[
  with_group=${default_group:-nobody}
  ]
)
AC_SUBST([pkgsysuser],[$with_user])
AC_SUBST([pkgsysgroup],[$with_group])

AC_ARG_WITH([build-number],
  [AS_HELP_STRING([--with-build-number],[specify a version string for this build])],
  [ build_number="$withval" ]
)

#
# Build environment
#
build_person="`id -nu`"
build_group="`id -ng`"
build_machine="`uname -n`"
AC_SUBST([build_machine])
AC_SUBST([build_person])
AC_SUBST([build_group])
AC_SUBST([build_number])

# -----------------------------------------------------------------------------
# 2. SITE CONFIGURATION

#
# Debug
#

AC_MSG_CHECKING([whether to enable debugging])
AC_ARG_ENABLE([debug],
  [AS_HELP_STRING([--enable-debug],[turn on debugging])],
  [],
  [enable_debug=no]
)
AC_MSG_RESULT([$enable_debug])

#
# Enable -Werror. We want this enabled by default for developers, but disabled by default
# for end users (because we don't want released versions to suffer from compiler warning hell).
#
AC_MSG_CHECKING([whether to enable -Werror])
AC_ARG_ENABLE([werror],
  [AS_HELP_STRING([--enable-werror],[turn compiler warnings into errors @<:@default=auto@:>@])],
  [],
  [
    case $TS_VERSION_STRING in
      *dev) enable_werror=yes ;;
      *) enable_werror=no ;;
    esac
  ]
)
AC_MSG_RESULT([$enable_werror])


#
# Fast SDK APIs, this disables the parameter checks (assert)
# on all APIs.
#

AC_MSG_CHECKING([whether to enable fast SDK APIs])
AC_ARG_ENABLE([fast-sdk],
  [AS_HELP_STRING([--enable-fast-sdk],[enable fast SDK APIs (no input parameter sanity checks)])],
  [],
  [enable_fast_sdk=no]
)
AC_MSG_RESULT([$enable_fast_sdk])
TS_ARG_ENABLE_VAR([use], [fast-sdk])
AC_SUBST(use_fast_sdk)

#
# Diags
#

AC_MSG_CHECKING([whether to enable diags])
AC_ARG_ENABLE([diags],
  [AS_HELP_STRING([--disable-diags],[turn off diags])],
  [],
  [enable_diags=yes]
)
AC_MSG_RESULT([$enable_diags])
TS_ARG_ENABLE_VAR([use], [diags])
AC_SUBST(use_diags)

#
# Build regression tests?
#

AC_MSG_CHECKING([whether to enable regression tests])
AC_ARG_ENABLE([tests],
  [AS_HELP_STRING([--disable-tests],[turn off regression tests])],
  [],
  [enable_tests=yes]
)
AC_MSG_RESULT([$enable_tests])
TS_ARG_ENABLE_VAR([has], [tests])
AC_SUBST(has_tests)
AM_CONDITIONAL([BUILD_TESTS], [test 0 -ne $has_tests])

#
# Force some static linkage (for testing / development only)
#
AC_MSG_CHECKING([whether to build a static traffic_server binary])
AC_ARG_ENABLE([static-proxy], [AS_HELP_STRING([--enable-static-proxy],[build a static traffic_server binary])], [
    AC_ENABLE_STATIC
  ], [
    AC_DISABLE_STATIC
    enable_static_proxy=no
  ]
)
AC_MSG_RESULT([$enable_static_proxy])
TS_ARG_ENABLE_VAR([has],[static-proxy])
AM_CONDITIONAL([BUILD_STATIC_PROXY], [test 0 -ne $has_static_proxy])

#
# Remote Coverity Prevent commit
#
AC_MSG_CHECKING([whether to commit cov defects to remote host])
AC_ARG_ENABLE([remote-cov-commit],
  [AS_HELP_STRING([--enable-remote-cov-commit[=HOST]], [commit cov defects to remote host [HOST=localhost]])],
  [],
  [enable_remote_cov_commit=localhost]
)
AC_MSG_RESULT([$enable_remote_cov_commit])
AC_SUBST([enable_remote_cov_commit])

#
# WCCP
#
AC_MSG_CHECKING([whether to enable WCCP v2 support])
AC_ARG_ENABLE([wccp],
  [AS_HELP_STRING([--enable-wccp],[enable WCCP v2])],
  [],
  [enable_wccp=no]
)
AC_MSG_RESULT([$enable_wccp])
TS_ARG_ENABLE_VAR([has],[wccp])
AC_SUBST(has_wccp)
AM_CONDITIONAL([BUILD_WCCP], [test 0 -ne $has_wccp])

#
# InterimCache
#
AC_MSG_CHECKING([whether to enable interim cache support])
AC_ARG_ENABLE([interim_cache],
  [AS_HELP_STRING([--enable-interim-cache],[enable interim cache])],
  [],
  [enable_interim_cache=no]
)
AC_MSG_RESULT([$enable_interim_cache])
TS_ARG_ENABLE_VAR([has],[interim_cache])
AC_SUBST(has_interim_cache)
AM_CONDITIONAL([BUILD_INTERIM_CACHE], [test 0 -ne $has_interim_cache])

# Google profiler
AC_MSG_CHECKING([whether to enable profiler])
AC_ARG_WITH([profiler],
  [AS_HELP_STRING([--with-profiler],[enable support for profiler [default=no]])],
  [with_profiler=$withval],
  [with_profiler=no]
)
AC_MSG_RESULT([$with_profiler])

#
# use eventfd() or pipes
# Found that ec2 is using an older kernel causing eventfd errors.
# Disable eventfd when using ATS on EC2 Fedora.
#
AC_MSG_CHECKING([whether to enable eventfd()])
AC_ARG_ENABLE([eventfd],
  [AS_HELP_STRING([--disable-eventfd],[turn off eventfd and use pipes])],
  [],
  [enable_eventfd="yes"]
)
AC_MSG_RESULT([$enable_eventfd])

#
# use POSIX capabilities instead of user ID switching.
#
AC_MSG_CHECKING([whether to use POSIX capabilities])
AC_ARG_ENABLE([posix-cap],
  [AS_HELP_STRING([--disable-posix-cap],[Use user id switching instead of POSIX capabilities])],
  [],
  [enable_posix_cap="auto"]
)
AC_MSG_RESULT([$enable_posix_cap])

#
# use hwloc library when possible (can be disabled)
#
AC_MSG_CHECKING([whether to use hwloc library])
AC_ARG_ENABLE([hwloc],
  [AS_HELP_STRING([--disable-hwloc],[Don't use the hwloc library])],
  [],
  [enable_hwloc="yes"]
)
AC_MSG_RESULT([$enable_hwloc])

#
# Enble ccache explicitly (it's disabled by default, because of build problems in some cases)
#
AC_MSG_CHECKING([whether to enable ccache])
AC_ARG_ENABLE([ccache],
  [AS_HELP_STRING([--enable-ccache],[Enable ccache (for developers)])],
  [],
  [enable_ccache="no"]
)
AC_MSG_RESULT([$enable_ccache])

#
# Use TPROXY for connection transparency.
#
AC_MSG_CHECKING([whether to enable TPROXY based transparency])
AC_ARG_ENABLE([tproxy],
  [AS_HELP_STRING([--enable-tproxy[[=ARG]]],
                  [Use TPROXY to enable connection transparency.
                   'auto' or omitted for local system default,
                   'no' to disable,
                   'force' to use built in default,
                   number to use as IP_TRANSPARENT sockopt.
                   [default=auto]
                  ])
  ],
  [],
  [enable_tproxy="auto"]
)
AC_MSG_RESULT([$enable_tproxy])

#
# Disable our freelist implementation, reverting it to whatever
# allocator (malloc, tcmalloc or jemalloc) that is in use. This is
# useful for debugging.
#
AC_MSG_CHECKING([whether to disable freelist])
AC_ARG_ENABLE([freelist],
  [AS_HELP_STRING([--disable-freelist],[turn off freelist and use allocators])],
  [],
  [enable_freelist="yes"]
)
AC_MSG_RESULT([$enable_freelist])
TS_ARG_ENABLE_VAR([use], [freelist])
AC_SUBST(use_freelist)

#
# The original InkFreeList memory pool could not reclaim itself
# automatically. We can use '--enable-reclaimable-freelist' option
# to enable the reclaiming feature. This option is effective only
# when freelist is enable.
#
if test "x${enable_freelist}" = "xyes"; then
  AC_MSG_CHECKING([whether to enable reclaimable freelist])
  AC_ARG_ENABLE([reclaimable-freelist],
                [AS_HELP_STRING([--enable-reclaimable-freelist],
                                [enable reclaimable freelist support (effective only when freelist is enabled)])],
                [],
                [enable_reclaimable_freelist="no"])
  AC_MSG_RESULT([$enable_reclaimable_freelist])
else
  enable_reclaimable_freelist="no"
fi
TS_ARG_ENABLE_VAR([use], [reclaimable_freelist])
AC_SUBST(use_reclaimable_freelist)

#
# Options for SPDY
#
AC_MSG_CHECKING([whether to enable spdy])
AC_ARG_ENABLE([spdy],
        [AS_HELP_STRING([--enable-spdy], [turn on spdy protocol])],
        [],
        [enable_spdy="no"])
AC_MSG_RESULT([$enable_spdy])
TS_ARG_ENABLE_VAR([has], [spdy])
AC_SUBST(has_spdy)
AM_CONDITIONAL([BUILD_SPDY], [test 0 -ne $has_spdy])

#
# Configure how many stats to allocate for plugins. Default is 512.
#
AC_ARG_WITH([max-api-stats],
  [AS_HELP_STRING([--with-max-api-stats],[max number of plugin stats [default=512]])],
  [max_api_stats=$withval],
  [max_api_stats=512]
)
AC_SUBST(max_api_stats)

#
# Max host name length that we deal with in URLs.
#
AC_ARG_WITH([max-host-name-len],
  [AS_HELP_STRING([--with-max-host-name-len],[max host name length [default=256]])],
  [max_host_name_len=$withval],
  [max_host_name_len=256]
)
AC_SUBST(max_host_name_len)

#
# EventProcessor thread configurations
#

AC_ARG_WITH([max-event-threads],
  [AS_HELP_STRING([--with-max-event-threads],[max number of event threads [default=4096]])],
  [max_event_threads=$withval],
  [max_event_threads=4096]
)
AC_SUBST(max_event_threads)

AC_ARG_WITH([max-threads-per-type],
  [AS_HELP_STRING([--with-max-threads-per-type],[max number of threads per event type [default=3072]])],
  [max_threads_per_type=$withval],
  [max_threads_per_type=3072]
)
AC_SUBST(max_threads_per_type)

#
# Experimental plugins
#

AC_MSG_CHECKING([whether to enable experimental plugins])
AC_ARG_ENABLE([experimental-plugins],
  [AS_HELP_STRING([--enable-experimental-plugins],[build experimental plugins])],
  [],
  [enable_experimental_plugins=no]
)
AC_MSG_RESULT([$enable_experimental_plugins])
AM_CONDITIONAL([BUILD_EXPERIMENTAL_PLUGINS], [ test "x${enable_experimental_plugins}" = "xyes" ])

#
# Example plugins. The example plugins are always built, but not always installed. Installing
# them is useful for QA, but not useful for most users, so we default this to disabled.
#

AC_MSG_CHECKING([whether to install example plugins])
AC_ARG_ENABLE([example-plugins],
  [AS_HELP_STRING([--enable-example-plugins],[install example plugins])],
  [],
  [enable_example_plugins=no]
)
AC_MSG_RESULT([$enable_example_plugins])
AM_CONDITIONAL([BUILD_EXAMPLE_PLUGINS], [ test "x${enable_example_plugins}" = "xyes" ])


#
# Test tools. The test tools are always built, but not always installed. Installing
# them is useful for QA, but not useful for most users, so we default this to disabled.
#

AC_MSG_CHECKING([whether to install testing tools])
AC_ARG_ENABLE([test-tools],
  [AS_HELP_STRING([--enable-test-tools],[install testing tools])],
  [],
  [enable_test_tools=no]
)
AC_MSG_RESULT([$enable_test_tools])
AM_CONDITIONAL([BUILD_TEST_TOOLS], [ test "x${enable_test_tools}" = "xyes" ])

#
# build c++ api
#
AC_MSG_CHECKING([whether to build c++ api])
AC_ARG_ENABLE([cppapi],
  [AS_HELP_STRING([--enable-cppapi],[Build the c++ api])],
  [],
  [enable_cppapi="no"]
)
AC_MSG_RESULT([$enable_cppapi])
AM_CONDITIONAL([ENABLE_CPPAPI], [ test "x${enable_cppapi}" = "xyes" ])

#
# Disable LuaJIT? This is a interrim option, when Lua becomes part of the core
# requirements, we will remove this option.
#
AC_MSG_CHECKING([whether to disable LuaJIT])
AC_ARG_ENABLE([luajit],
  [AS_HELP_STRING([--disable-luajit],[turn off LuaJIT])],
  [],
  [enable_luajit="yes"]
)
AC_MSG_RESULT([$enable_luajit])
AM_CONDITIONAL([BUILD_LUAJIT], [ test "x${enable_luajit}" = "xyes" ])

#
# Installation directories
# For each var the following is evaluated
# foo      Standard variable  eg. ${prefix}/foo
# rel_foo  Relative to prefix eg. foo
#
TS_SUBST_LAYOUT_PATH([prefix])
TS_SUBST_LAYOUT_PATH([exec_prefix])
TS_SUBST_LAYOUT_PATH([bindir])
TS_SUBST_LAYOUT_PATH([sbindir])
TS_SUBST_LAYOUT_PATH([libdir])
TS_SUBST_LAYOUT_PATH([libexecdir])
TS_SUBST_LAYOUT_PATH([infodir])
TS_SUBST_LAYOUT_PATH([mandir])
TS_SUBST_LAYOUT_PATH([sysconfdir])
TS_SUBST_LAYOUT_PATH([datadir])
TS_SUBST_LAYOUT_PATH([installbuilddir])
TS_SUBST_LAYOUT_PATH([includedir])
TS_SUBST_LAYOUT_PATH([localstatedir])
TS_SUBST_LAYOUT_PATH([runtimedir])
TS_SUBST_LAYOUT_PATH([logdir])
TS_SUBST_LAYOUT_PATH([cachedir])
TS_SUBST_LAYOUT_PATH([docdir])

TS_SUBST([pkgbindir])
TS_SUBST([pkgsbindir])
TS_SUBST([pkglibdir])
TS_SUBST([pkglibexecdir])
TS_SUBST([pkgsysconfdir])
TS_SUBST([pkgdatadir])
TS_SUBST([pkglocalstatedir])
TS_SUBST([pkgruntimedir])
TS_SUBST([pkglogdir])
TS_SUBST([pkgcachedir])
TS_SUBST([pkgdocdir])


# -----------------------------------------------------------------------------
# 3. CHECK FOR PROGRAMS

# Compiler selection:
#
# Implementation note (toc)
# 1) Get default compiler settings (case statement.)
# 2) Check for over-rides of default compiler.
# 3) Set standard CFLAGS, SHARED_CFLAGS, etc.
# 4) (in first kludge mode block...) obtain any further CFLAG-type additions.
# 5) Test compilers with all flags set.

# AC_PROG can sometimes mangle CFLAGS etc.
# in particular, on Linux they insert -g -O2, here we preserve any user CFLAGS
_ts_saved_CFLAGS="${CFLAGS}"
_ts_saved_CXXFLAGS="${CXXFLAGS}"

# We force the compiler search list because the default GCC on Darwin cannot build
# Traffic Server. On most (all?) platforms, cc and c++ should be the preferred default
# compiler.
AC_PROG_CC([cc gcc clang icc])
AC_PROG_CXX([c++ g++ clang++ icpc])

AM_PROG_CC_C_O
AC_PROG_CPP
AC_PROG_CXXCPP
AM_PROG_AS

AX_COMPILER_VENDOR

CFLAGS="${_ts_saved_CFLAGS}"
CXXFLAGS="${_ts_saved_CXXFLAGS}"

# AX_CXX_COMPILE_STDCXX_11 requires the current language to be C++.
AC_LANG_PUSH([C++])

AX_CXX_COMPILE_STDCXX_11( [noext], [enable_cxx_11_support=yes], [
  enable_cxx_11_support=no
  AC_MSG_NOTICE([disabling features that depend on C++11 support])
])

AM_CONDITIONAL([BUILD_HAVE_CXX_11], [ test "x${enable_cxx_11_support}" = "xyes" ])
if test "x${enable_cxx_11_support}" = "xyes" ; then
  AC_DEFINE(HAVE_CXX_11, 1, [Whether the compiler support C++11])
fi

# While we are in C++ mode, check for the GNU hash_map extension.
AC_CHECK_HEADERS([unordered_map unordered_set], [], [],
[[#ifdef HAVE_UNORDERED_MAP
#include <unordered_map>
#endif
]])

AC_MSG_CHECKING([for <ext/hash_map>])
AC_COMPILE_IFELSE([
  AC_LANG_PROGRAM([
    #include <string>
    #include <ext/hash_map>
    ], [
     __gnu_cxx::hash_map<std::string, std::string> map;
  ])],
  [ have_gnu_cxx_hash_map=yes ],
  [ have_gnu_cxx_hash_map=no ]
)

AC_MSG_RESULT([$have_gnu_cxx_hash_map])
if test "x${have_gnu_cxx_hash_map}" = "xyes" ; then
  AC_DEFINE(HAVE_GNU_CXX_HASH_MAP, 1, [whether __gnu_cxx::hash_map is available])
fi

# And check for std::shared_ptr vs std::tr1::shared_ptr
AC_MSG_CHECKING([for std::shared_ptr])
AC_COMPILE_IFELSE([
  AC_LANG_PROGRAM([
    #include <memory>
    using std::shared_ptr;
    ], [
  ])],
  [ have_std_shared_ptr=yes ],
  [ have_std_shared_ptr=no ]
)

AC_MSG_RESULT([$have_std_shared_ptr])
if test "x${have_std_shared_ptr}" = "xyes" ; then
  AC_DEFINE(HAVE_STD_SHARED_PTR, 1, [whether std::shared_ptr is available])
fi

AC_LANG_POP()

dnl AC_PROG_SED is only available from version 2.6 (released in 2003). CentosOS
dnl 5.9 still has an ancient version, but we have macros that require
dnl AC_PROG_SED. The actual AC_PROG_SED macro does functional checks, but here
dnl we define a trivial local version for times when we are running on
dnl obsoldete autoconf.
ifdef([AC_PROG_SED], [], [
  AC_DEFUN([AC_PROG_SED], [
    AC_CHECK_PROG(SED, sed, sed)
  ])
])


# Various OS specific setup. Note that on Solaris, 32-bit is always the
# default, even on a box that with 64-bit architecture.
# This also sets up a "normalized" variable and define $host_os_def.
defer_accept=1
case $host_os in
  linux*)
    host_os_def="linux"
    defer_accept=45
    EXTRA_CXX_LDFLAGS="-rdynamic"
    ;;
  darwin*)
    host_os_def="darwin"
    ;;
  freebsd*)
    host_os_def="freebsd"
    EXTRA_CXX_LDFLAGS="-rdynamic"
    TS_ADDTO(CPPFLAGS, [-I/usr/local/include])
    ;;
  kfreebsd*)
    host_os_def="freebsd"
    EXTRA_CXX_LDFLAGS="-rdynamic"
    TS_ADDTO(CPPFLAGS, [-I/usr/local/include])
    TS_ADDTO(CPPFLAGS, [-Dkfreebsd])
    ;;
  openbsd*)
    host_os_def="openbsd"
    ;;
  solaris*)
    host_os_def="solaris"
    case "`isalist`" in
      *amd64*)
        TS_ADDTO(CFLAGS, -m64)
        TS_ADDTO(CXXFLAGS, -m64)
        TS_ADDTO(LUA_LDFLAGS, -m64)
        ;;
    esac
    ;;
  *)
    EXTRA_CXX_LDFLAGS="-rdynamic"
    host_os_def=unknown
    ;;
esac

TS_ADDTO(CPPFLAGS, [-D$host_os_def])
AC_SUBST(defer_accept)


dnl AM_PROG_AR is not always available, but it doesn't seem to be needed in older versions.
ifdef([AM_PROG_AR],
      [AM_PROG_AR])

AC_PROG_AWK
AC_PROG_SED
AC_PROG_LN_S
AC_PROG_INSTALL
AC_PROG_LIBTOOL
AC_CHECK_PROG(RM, rm, rm)
AC_CHECK_PROG(ASCPP, cpp, cpp)
AC_CHECK_TOOL(AR, ar, ar)
AC_ISC_POSIX

AM_PATH_PYTHON([2.4], [
  dnl action-if-found
  TS_MAN1_MANPAGES=`cd $srcdir/doc && $PYTHON manpages.py --section=1 | $AWK '{print "$(BUILDDIR)/man/" $0 }' | tr '\n' ' '`
  TS_MAN3_MANPAGES=`cd $srcdir/doc && $PYTHON manpages.py --section=3 | $AWK '{print "$(BUILDDIR)/man/" $0 }' | tr '\n' ' '`
  TS_MAN5_MANPAGES=`cd $srcdir/doc && $PYTHON manpages.py --section=5 | $AWK '{print "$(BUILDDIR)/man/" $0 }' | tr '\n' ' '`
  TS_MAN8_MANPAGES=`cd $srcdir/doc && $PYTHON manpages.py --section=8 | $AWK '{print "$(BUILDDIR)/man/" $0 }' | tr '\n' ' '`

  # If we have python, check if the Sphinx version looks OK.
  AS_IF(["$PYTHON" "$srcdir/doc/checkvers.py" --check-version], [
    sphinx_version_check=yes
  ])

], [
  dnl action-if-not-found
  :
])

AC_ARG_VAR(SPHINXBUILD, [the sphinx-build documentation generator])
AC_ARG_VAR(SPHINXOPTS, [additional sphinx-build options])
AC_CHECK_PROG([SPHINXBUILD], [sphinx-build], [sphinx-build], [false])

AC_SUBST(TS_MAN1_MANPAGES)
AC_SUBST(TS_MAN3_MANPAGES)
AC_SUBST(TS_MAN5_MANPAGES)
AC_SUBST(TS_MAN8_MANPAGES)

AC_MSG_CHECKING([whether to build man pages])
AS_IF([test "x$sphinx_version_check" = "xyes" -a "x$SPHINXBUILD" != "xfalse"], [
  AM_CONDITIONAL([BUILD_MANPAGES], [true])
  AC_MSG_RESULT([yes])
], [
  AM_CONDITIONAL([BUILD_MANPAGES], [false])
  AC_MSG_RESULT([no])
])

# Do bison check by hand because we must do a version check.
# Use YACC because it makes autotools shut up.
BISON_MAJOR=2
BISON_MINOR=4
BISON_POINT=1
AC_CHECK_PROG([YACC],[bison],[bison])
AS_IF([test -n "$YACC"],
      [ bison_version_check=`$YACC --version 2>&1 | \
        $SED -n '/bison/s/^[[^0-9]]*\([[0-9]][[0-9.]]*\).*$/\1/p' | \
        $AWK "{ if (\\$1 > $BISON_MAJOR || (\\$1 == $BISON_MAJOR && (\\$2 > $BISON_MINOR || (\\$2 == $BISON_MINOR && (NR == 2 || \\$3 >= $BISON_POINT))))) print \"yes\"; else printf(\"version %d.%d.%d\",\\$1,\\$2,\\$3); }" FS=. \
        `
        AS_IF([test "x$bison_version_check" != "xyes"],
          [ YACC=''
            AS_IF([test -z "$bison_version_check"],
              [bison_version_check='no version data']
            )
          ]
        )
      ],
      [ YACC=''
        bison_version_check="nothing"
      ]
)
# Check lex/flex by hand because we need flex of a sufficient version.
FLEX_MAJOR=2
FLEX_MINOR=5
FLEX_POINT=33
dnl ylwrap requires the lexer executable to be an absolute path or in the srcdir.
dnl but we need various other LEX values.
AC_PROG_LEX
AS_IF([test -n "$LEX"],
      [ flex_version_check=`$LEX --version 2>&1 | \
        $SED -n '/flex/s/^[[^0-9]]*\([[0-9]][[0-9.]]*\)[[^0-9]]*.*$/\1/p' | \
        $AWK "{ if (\\$1 > $FLEX_MAJOR || (\\$1 == $FLEX_MAJOR && (\\$2 > $FLEX_MINOR || (\\$2 == $FLEX_MINOR && (NR == 2 || \\$3 >= $FLEX_POINT))))) print \"yes\"; else printf(\"version %d.%d.%d\",\\$1,\\$2,\\$3); }" FS=. \
        `
        AS_IF([test "x$flex_version_check" != "xyes"],
          [ LEX=''
            AS_IF([test -z "$flex_version_check"],
              [flex_version_check='no version data']
            )
          ]
        )
      ],
      [ LEX=''
        flex_version_check="nothing"
      ]
)

# Generated files checked in, only build them if the local OS has the necessary support.
# Otherwise just use the checked in version.
AM_CONDITIONAL([BUILD_TSCONFIG_GRAMMAR], [ test -n "$LEX" && test -n "$YACC" ])

# Check for Perl and Doxygen
AC_PATH_PROG([DOXYGEN], [doxygen]) # needed for Doxygen
AC_PATH_PROG([PERL], [perl],[not found])
AS_IF([test "x$PERL" = "xnot found"],
  [AC_MSG_ERROR([check for perl failed. Have you installed perl?])]
)
AC_ARG_VAR([DOXYGEN], [full path of Doxygen executable])
AC_ARG_VAR([PERL], [full path of Perl executable])

# Check if MakeMaker is available
AX_PROG_PERL_MODULES([ExtUtils::MakeMaker], AM_CONDITIONAL([BUILD_PERL_LIB], [true]),
                                            AM_CONDITIONAL([BUILD_PERL_LIB], [false])
)

# Check for GNU-style -On optimization flags
AC_MSG_CHECKING([checking whether to auto-set compiler optimization flags])
has_optimizer_flags=`echo "$CFLAGS $CXXFLAGS" | ${AWK} '$0 !~ /-O.?/{print "no"}'`
AS_IF([test "x${has_optimizer_flags}" = "xno"],
        [
                optimizing_flags='-O3'
                AC_MSG_RESULT([yes ${optimizing_flags}])
        ],
        [
                has_optimizer_flags='yes'
                optimizing_flags=''
                AC_MSG_RESULT([no])
        ]
)

AM_CONDITIONAL([BUILD_HAVE_LIBCXX], [ false ])

case $host_os_def in
  linux)
    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xintel"], [
      # -Wall goes crazy, so turned these specific checks off for now:
      #
      #  111 is "statement is unreachable"
      #  279 is "controlling expression is constant", triggered by our asserts
      #  383 is "value copied to temporary, reference to temporary used"
      #  444 is "destructor for base class is not virtual"
      #  522 is "function "xyz" redeclared "inline" after being called
      #  873 is "has no corresponding operator delete". ToDo: we should fix.
      #  981 is "operands are evaluated in unspecified order"
      # 1418 is "external function definition with no prior declaration"
      # 1419 is "external declaration in primary source file"
      # 1572 is "floating-point equality and inequality comparisons are unreliable"
      # 1720 is "operator new" has no corresponding member operator delete"
      # 2256 is "non-pointer conversion from "int" to "unsigned char" "
      # 2259 is "non-pointer conversion from "int" to "unsigned char" "
      #
      # TODO: We should try to eliminate more of these -wd exclusions.
      common_opt="-pipe -Wall -wd111 -wd279 -wd383 -wd522 -wd444 -wd873 -wd981 -wd1418 -wd1419 -wd1572 -wd1720 -wd2256 -wd2259"
      debug_opt="-ggdb3 $common_opt"
      release_opt="-g $common_opt $optimization_flags -axsse4.2 -fno-strict-aliasing"
      cxx_opt="-Wno-invalid-offsetof"
    ])

    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xclang"], [
      debug_opt="-ggdb3 $common_opt -Qunused-arguments"
      release_opt="-g $common_opt $optimizing_flags -fno-strict-aliasing -Qunused-arguments"
      cxx_opt="-Wno-invalid-offsetof -Qunused-arguments"
    ])

    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xgnu"], [
      # This is useful for finding odd conversions
      #    common_opt="-pipe -Wall -Wconversion -Wno-sign-conversion"
      ts_am_common_flags="-Wunused-parameter"
      common_opt="-pipe -Wall"
      debug_opt="-ggdb3 $common_opt"
      release_opt="-g $common_opt $optimizing_flags -feliminate-unused-debug-symbols -fno-strict-aliasing"
      cxx_opt="-Wno-invalid-offsetof"
      # Special options for flex generated .c files
      flex_cflags="-Wno-unused-parameter"
    ])

    ;; # linux)

  darwin)
    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xclang"], [
      common_opt="-pipe -Wall -Wno-deprecated-declarations -Qunused-arguments"
      debug_opt="-g $common_opt"
      release_opt="-g $common_opt $optimizing_flags -fno-strict-aliasing"
      cxx_opt="-Wno-invalid-offsetof"
    ], [
      AC_MSG_WARN([clang is the only supported compiler on Darwin])
    ])

    # Darwin needs to use libc++ for any C++11 code.
    AM_CONDITIONAL([BUILD_HAVE_LIBCXX], [ true ])

    # NOTE: This seems semi-kludgy, but useful for MacPorts I think.
    AS_IF([test -d /opt/local/include], [
      TS_ADDTO(CPPFLAGS, [-I/opt/local/include])
    ])
    AS_IF([test -d /opt/local/lib], [
      TS_ADDTO(LDFLAGS, [-L/opt/local/lib])
    ])

    ;; # darwin)

  freebsd|kfreebsd)
    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xclang"], [
      common_opt="-pipe -Wall -Qunused-arguments"
      debug_opt="-ggdb3 $common_opt"
      release_opt="-g $common_opt $optimizing_flags -feliminate-unused-debug-symbols -fno-strict-aliasing"
      cxx_opt="-Wno-invalid-offsetof -Qunused-arguments"
    ])

    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xgnu"], [
      common_opt="-pipe -Wall"
      debug_opt="-ggdb3 $common_opt"
      release_opt="-g $common_opt $optimizing_flags -feliminate-unused-debug-symbols -fno-strict-aliasing"
      cxx_opt="-Wno-invalid-offsetof"
    ])

    AS_IF([test -d /usr/local/lib], [
      TS_ADDTO(LDFLAGS, [-L/usr/local/lib])
    ])

    ;; # freebsd|kfreebsd)

  solaris)
    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xgnu"], [
      common_opt="-pipe -Wall"
      debug_opt="-ggdb3 $common_opt"
      release_opt="-g $common_opt $optimizing_flags -feliminate-unused-debug-symbols -fno-strict-aliasing"
      cxx_opt="-Wno-invalid-offsetof"
    ])

    ;; # solaris)

  *)
    # Not sure what platform this is, but take a stab at some general GCC options ...
    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xgnu"], [
      common_opt="-pipe -Wall"
      debug_opt="-ggdb3 $common_opt"
      release_opt="-g $common_opt $optimizing_flags -feliminate-unused-debug-symbols -fno-strict-aliasing"
      cxx_opt="-Wno-invalid-offsetof"
    ])
esac

# Only add -Werror if the user has requested it. We enable this by default for
# development, disable it by default for release.
AS_IF([test x"$enable_werror" = xyes], [
  TS_ADDTO(release_opt, -Werror)
  TS_ADDTO(debug_opt, -Werror)
])

cc_oflag_opt=$release_opt
cc_oflag_dbg=$debug_opt
cxx_oflag_opt="$release_opt $cxx_opt $cxx_rel"
cxx_oflag_dbg="$debug_opt $cxx_opt $cxx_dbg"

AM_CFLAGS="$ts_am_common_flags"
AM_CXXFLAGS="$ts_am_common_flags"
AC_SUBST(AM_CFLAGS)
AC_SUBST(AM_CXXFLAGS)

AC_SUBST([FLEX_CFLAGS], $flex_cflags)

SHARED_CFLAGS=-fPIC
SHARED_LDFLAGS=-shared
SHARED_CXXFLAGS=-fPIC
SHARED_CXXLINKFLAGS=-shared

#
# _Here_ is where we go ahead and add the _optimizations_ to already
#  existing CFLAGS/CXXFLAGS if some special values had been set.
#
if test "x${enable_debug}" = "xyes"; then
  TS_ADDTO(CFLAGS, [${cc_oflag_dbg}])
  TS_ADDTO(CXXFLAGS, [${cxx_oflag_dbg}])
  TS_ADDTO(CPPFLAGS, [-DDEBUG -D_DEBUG])
else
  TS_ADDTO(CFLAGS, [${cc_oflag_opt}])
  TS_ADDTO(CXXFLAGS, [${cxx_oflag_opt}])
fi

# Checks for pointer size
AC_CHECK_SIZEOF([void*])
if test "x$ac_cv_sizeof_voidp" == "x"; then
  AC_ERROR([Cannot determine size of void*])
fi
AC_SUBST(ac_cv_sizeof_voidp)


#
# Here are all the extra linux-specific C(XX)FLAGS additions and
# so forth.
# TODO cpu architecture settings separate from operating system settings
#
cpu_architecture=""
# GCC: add a default march if there is not one set
if test "x${GCC}" = "xyes"; then
  if test "${ac_cv_sizeof_voidp}" = "4"; then
    case "$host_cpu" in
      i?86* | k[5-8]* | pentium* | athlon)
        cpu_architecture="-march=i586"
      ;;
    esac
  else
    case "$host_cpu" in
      x86_64 | amd64)
        # XXX: Any need for 64-bit arch flags?
        # cpu_architecture="-march=native"
      ;;
    esac
  fi
fi

# Overrride detected architecture with the user suplied one
#
AC_ARG_WITH(architecture, [AC_HELP_STRING([--with-architecture=ARCH],[use a specific CPU architecture])],
[
  if test "x$withval" != "xyes" && test "x$withval" != "xno"; then
    case "$withval" in
      -*)
        # TODO: In case we are cross compiling some of the provided flags
        #       should be added to the LDFLAGS
        cpu_architecture="$withval"
      ;;
      *)
        cpu_architecture="-march=$withval"
      ;;
    esac
  elif test "x$withval" = "x"; then
    AC_MSG_ERROR([--with-architecture requires an param])
  fi
])

if test "x$cpu_architecture" != "x"; then
  TS_ADDTO(CFLAGS, [$cpu_architecture])
  TS_ADDTO(CXXFLAGS, [$cpu_architecture])
fi

# 64-bit LFS support
#
TS_ADDTO(CPPFLAGS, [-D_LARGEFILE64_SOURCE=1])
if test "${ac_cv_sizeof_voidp}" = "8"; then
  TS_ADDTO(CPPFLAGS, [-D_COMPILE64BIT_SOURCE=1])
else
  TS_ADDTO(CPPFLAGS, [-D_FILE_OFFSET_BITS=64])
fi
TS_ADDTO(CPPFLAGS, [-D_GNU_SOURCE])
TS_ADDTO(CPPFLAGS, [-D_REENTRANT])
TS_ADDTO(CPPFLAGS, [-D__STDC_LIMIT_MACROS=1])
TS_ADDTO(CPPFLAGS, [-D__STDC_FORMAT_MACROS=1])

AC_MSG_NOTICE([Build for host OS: $host_os, arch: $host_cpu, optimization: $host_os_def])

#
# Note:  These are site-specific macro's that do various tests
#         on the selected compilers.  There was some tunning
#         associated with our not wanting to use GNU for _everything_.
# Note:  This macro may set certain parameters when run.
#

#
# CPP 11 API
# TODO: briang, this needs to be translated to a define
# that can be used in the c++ api to enable c++11 api features.
#
#AC_MSG_CHECKING([whether to enable c++11 api])
#AC_ARG_WITH([cpp11api],
#  [AS_HELP_STRING([--with-cpp11api],[enable support for cpp11api [default=auto]])],
#  [cpp11api=$withval],
#  [cpp11api=$enable_cxx_11_support]
#)
#AC_MSG_RESULT([$cpp11api])
#AM_CONDITIONAL([BUILD_CPP11API], [test "$cpp11api" = yes])

# Check for ccache (if explicitly enabled)
if test "x$enable_ccache" = "xyes"; then
    AC_CHECK_PROG([CCACHE],[ccache],[ccache],[])
    if test "x${CCACHE}" = "xccache"; then
        CC="$CCACHE $CC"
        CXX="$CCACHE $CXX"
    fi
fi

# -----------------------------------------------------------------------------
# 4. CHECK FOR LIBRARIES

AC_SEARCH_LIBS([exc_capture_context], [exc], [], [])
AC_SEARCH_LIBS([MLD_demangle_string], [mld], [], [])
AC_SEARCH_LIBS([dlopen], [dl], [], [])
AC_SEARCH_LIBS([socket], [socket], [], [])
AC_SEARCH_LIBS([gethostbyname], [nsl], [], [])

dnl Linux has pthread symbol stubss in both libc ad libpthread, so it's important to test
dnl specifically for pthread_create() here.
AC_SEARCH_LIBS([pthread_create], [pthread], [], [])
AC_SEARCH_LIBS([clock_gettime], [rt], [], [])
AC_SEARCH_LIBS([clock_gettime], [posix4], [], [])

dnl XXX The following check incorrectly causes the build to succeed
dnl on Darwin. We should be using AC_SEARCH_LIBS, but rest_init is
dnl actually present in libsystem. We are searching for the library
dnl that contains the full Bind 9 API (which is acutally libresolv).
dnl However, the resolv API uses macros to rename it's APIs to per-version
dnl symbols, so standard autoconf macros cannot reasonably be used to
dnl check for it. We need to write custom macros to detect it properly.
AC_CHECK_LIB([resolv],[res_init],[AC_SUBST([LIBRESOLV],["-lresolv"])])
AC_CHECK_LIB([resolv],[__putlong],[AC_SUBST([LIBRESOLV],["-lresolv"])])

# Test for ncurses. We need to turn off -Werror because the C code in the
# ncurses compile tests does not generate unused variable warnings.
__saved_CFLAGS="$CFLAGS"
TS_REMOVEFROM(CFLAGS, -Werror)
AX_WITH_CURSES
CFLAGS="$__saved_CFLAGS"

AX_LIB_CURL([7.19], [
    AM_CONDITIONAL([BUILD_TSTOP], [test "x$ax_cv_curses" = "xyes"])
  ], [
    AM_CONDITIONAL([BUILD_TSTOP], [false])
  ]
)

#
# Check for SSL presence and usability
TS_CHECK_CRYPTO

#
# Check for NextProtocolNegotiation TLS extension support.
TS_CHECK_CRYPTO_NEXTPROTONEG

#
# Check for ALPN TLS extension support.
TS_CHECK_CRYPTO_ALPN
#
# Check for EC key support.
TS_CHECK_CRYPTO_EC_KEYS

#
# Check for ServerNameIndication TLS extension support.
TS_CHECK_CRYPTO_SNI

#
# Check for zlib presence and usability
TS_CHECK_ZLIB

#
# Check for lzma presence and usability
TS_CHECK_LZMA

#
# Tcl macros provided by build/tcl.m4
#
# this will error out if tclConfig.sh is not found
SC_PATH_TCLCONFIG

# if tclConfig.sh loads properly, assume libraries are there and working
SC_LOAD_TCLCONFIG

# expect tclConfig.sh to populate TCL_LIB_FLAG and TCL_INCLUDE_SPEC
if test "$host_os_def" == "darwin"; then
    TCL_LIB_SPEC="-ltcl" # OSX fails to populate this variable
fi
AC_SUBST([LIBTCL],[$TCL_LIB_SPEC])


if test "x${TCL_INCLUDE_SPEC}" != "x-I/usr/include"; then
   TS_ADDTO(CPPFLAGS, [$TCL_INCLUDE_SPEC])
fi

#
# Check for XML parser
#
TS_CHECK_XML
if test "x${enable_xml}" != "xyes"; then
  AC_MSG_ERROR([Need at least one XML library, --with-expat is supported])
fi

AC_CHECK_FUNCS([clock_gettime kqueue epoll_ctl posix_memalign posix_fadvise posix_madvise posix_fallocate inotify_init])
AC_CHECK_FUNCS([lrand48_r srand48_r port_create strlcpy strlcat sysconf getpagesize])
AC_CHECK_FUNCS([getreuid getresuid getresgid setreuid setresuid])

# Check for eventfd() and sys/eventfd.h (both must exist ...)
AC_CHECK_HEADERS([sys/eventfd.h], [
  AS_IF([test "x$enable_eventfd" = "xyes"], [
    AC_CHECK_FUNCS([eventfd])
  ]
)])

AC_CHECK_FUNCS(eventfd)

#
# Check for mcheck_pedantic(3)
#
AC_CHECK_HEADERS(mcheck.h)
AC_CHECK_FUNCS(mcheck_pedantic)

#
# Check for pcre library
#
TS_CHECK_PCRE
if test "x${enable_pcre}" != "xyes"; then
  AC_MSG_ERROR([Cannot find pcre library. Configure --with-pcre=DIR])
fi

has_backtrace=0
# Check for backtrace() support
AC_CHECK_HEADERS([execinfo.h], [has_backtrace=1],[])
if test "${has_backtrace}" = "1"; then
  # FreeBSD requires '/usr/ports/devel/libexecinfo' for gdb style backtrace() support
  AC_SEARCH_LIBS([backtrace], [execinfo], [have_backtrace_lib=yes])
else
  AC_MSG_WARN([No backtrace() support found])
fi
AC_SUBST(execinfoh)
AC_SUBST(has_backtrace)

# Remote process unwinding is only implemented on Linux because it depends on various Linux-specific
# features such as /proc filesystem nodes, ptrace(2) and waitpid(2) extensions.
AS_IF([test "$host_os_def" = "linux"], [
  PKG_CHECK_MODULES([LIBUNWIND], [libunwind-ptrace], [
    enable_remote_unwinding=yes
  ], [
    dnl no remote unwind support
  ])
])
TS_ARG_ENABLE_VAR([use], [remote_unwinding])
AC_SUBST(use_remote_unwinding)

use_epoll=0
use_kqueue=0
use_port=0
if test "$ac_cv_func_epoll_ctl" = "yes"; then
  use_epoll=1
  have_good_poller=1
  AC_MSG_NOTICE([Using epoll event interface])
elif test "$ac_cv_func_kqueue" = "yes"; then
  use_kqueue=1
  have_good_poller=1
  AC_MSG_NOTICE([Using kqueue event interface])
elif test "$ac_cv_func_port_create" = "yes"; then
  use_port=1
  have_good_poller=1
  AC_MSG_NOTICE([Using port event interface])
else
  AC_MSG_FAILURE([No suitable polling interface found])
fi
AC_SUBST(use_epoll)
AC_SUBST(use_kqueue)
AC_SUBST(use_port)

has_profiler=0
if test "x${with_profiler}" = "xyes"; then
  AC_SEARCH_LIBS([ProfilerStart], [profiler],
    [AC_SUBST([LIBPROFILER], ["-lprofiler"])
     has_profiler=1
    ],
    [AC_MSG_FAILURE([check for profiler failed. Have you installed google-perftools-devel?])],
  )
fi
AC_SUBST(has_profiler)

AC_MSG_CHECKING(for 128bit CAS support)
AC_LANG_PUSH([C++])

# We need to save and restore compiler flags around this whole block.
# TS_TRY_COMPILE_NO_WARNING will save and restore flags, so if we do that in the
# middle, then we can accidentally restore modified flags.
__saved_CXXFLAGS="${CXXFLAGS}"
__saved_CFLAGS="${CFLAGS}"

has_128bit_cas=0

TS_TRY_COMPILE_NO_WARNING([],[
    __int128_t x = 0;
    __sync_bool_compare_and_swap(&x,0,10);
  ], [
    AC_MSG_RESULT(yes)
    has_128bit_cas=1
  ], [
    dnl If 128bit CAS fails, try again with the -mcx16 option. GCC needs this;
    dnl clang doesn't; icc is unknown but presumed sane.
    TS_ADDTO(CXXFLAGS, [-mcx16])
    TS_ADDTO(CFLAGS, [-mcx16])
    TS_TRY_COMPILE_NO_WARNING([],[
        __int128_t x = 0;
        __sync_bool_compare_and_swap(&x,0,10);
      ], [
        AC_MSG_RESULT(yes)
        has_128bit_cas=1
      ], [
        AC_MSG_RESULT(no)
    ])
])

CXXFLAGS="${__saved_CXXFLAGS}"
CFLAGS="${__saved_CFLAGS}"
AC_LANG_POP
AC_SUBST(has_128bit_cas)

AS_IF([test "x$has_128bit_cas" = "x1"], [
  TS_ADDTO(CFLAGS, [-mcx16])
  TS_ADDTO(CXXFLAGS, [-mcx16])
])

# Check for POSIX capabilities library.
# If we don't find it, disable checking for header.
use_posix_cap=0
AS_IF([test "x$enable_posix_cap" != "xno"],
  AC_SEARCH_LIBS([cap_set_proc],[cap],
    [AC_SUBST([LIBCAP], ["-lcap"])
     use_posix_cap=1
    ],[
     AS_IF([test "x$enable_posix_cap" == "xyes"], [
      AC_MSG_FAILURE([POSIX capabilities enabled but system library not found.])
     ],[
      [enable_posix_cap=no]
    ]    )
   ]
  )
)
AC_SUBST(use_posix_cap)

#
# If the OS is linux, we can use the '--enable-linux-native-aio' option to
# replace the aio thread mode. Effective only on the linux system.
#

AC_MSG_CHECKING([whether to enable Linux native AIO])
AC_ARG_ENABLE([linux-native-aio],
  [AS_HELP_STRING([--enable-linux-native-aio], [enable native Linux AIO support @<:@default=no@:>@])],
  [enable_linux_native_aio="${enableval}"],
  [enable_linux_native_aio=no]
)

AS_IF([test "x$enable_linux_native_aio" = "xyes"], [
  if test $host_os_def  != "linux"; then
    AC_MSG_ERROR([Linux native AIO can only be enabled on Linux systems])
  fi

  AC_CHECK_HEADERS([libaio.h], [],
    [AC_MSG_ERROR([Linux native AIO requires libaio.h])]
  )

  AC_SEARCH_LIBS([io_submit], [aio], [],
    [AC_MSG_ERROR([Linux native AIO requires libaio])]
  )

])

AC_MSG_RESULT([$enable_linux_native_aio])
TS_ARG_ENABLE_VAR([use], [linux_native_aio])
AC_SUBST(use_linux_native_aio)

# Check for hwloc library.
# If we don't find it, disable checking for header.
use_hwloc=0
AS_IF([test "x$enable_hwloc" = "xyes"], [
  # Use pkg-config, because some distros (*cough* Ubuntu) put hwloc in unusual places.
  PKG_CHECK_MODULES([HWLOC], [hwloc], [
    SAVE_LIBS="$LIBS"
    LIBS="-lhwloc"
    AC_LANG_PUSH([C++])
    AC_MSG_CHECKING([for hwloc C++ linking])
    AC_LINK_IFELSE([
      AC_LANG_PROGRAM([#include <hwloc.h>],[hwloc_topology_t t; hwloc_topology_init(&t); hwloc_get_type_depth(t, HWLOC_OBJ_SOCKET);])],[
      use_hwloc=1
      AC_SUBST([HWLOC_CFLAGS])
      AC_SUBST([HWLOC_LIBS])
      AC_MSG_RESULT([yes])
      # Old versions of libhwloc don't have HWLOC_OBJ_PU.
      AC_CHECK_DECL(HWLOC_OBJ_PU,
        [AC_DEFINE(HAVE_HWLOC_OBJ_PU, 1, [Whether HWLOC_OBJ_PU is available])], [],
        [#include <hwloc.h>]
      )
    ], [
      AC_MSG_RESULT([no])
      AC_MSG_WARN([hwloc not linkable, try --disable-hwloc])
      AC_SUBST([HWLOC_CFLAGS],[""])
      AC_SUBST([HWLOC_LIBS],[""])
    ])
    AC_LANG_POP()
    LIBS="$SAVE_LIBS"
  ], [
    AC_MSG_WARN([hwloc not found, try --disable-hwloc])
    AC_SUBST([HWLOC_CFLAGS],[""])
    AC_SUBST([HWLOC_LIBS],[""])
  ])
])

AC_SUBST(use_hwloc)

#
# Check for Maxmind APIs / includes. TODO: Long term, it might make sense to support
# GeoIP as a "helper" plugin, which other plugins can then use. Such a plugin could
# then manage which libraries to use via explicit dlopen()'s.
#
enable_maxmind_geoip=no
TS_SEARCH_LIBRARY([GeoIP_id_by_code], [GeoIP], [
  GEOIP_LIBS=$ts_cv_search_GeoIP_id_by_code
  AC_CHECK_HEADERS([GeoIP.h], [ enable_maxmind_geoip=yes ])
])

AC_SUBST(GEOIP_LIBS)
AM_CONDITIONAL([BUILD_GEOIP_PLUGIN], [ test "x${enable_maxmind_geoip}" = x"yes" ])

# Right now, the healthcheck plugins requires inotify_init (and friends)
AM_CONDITIONAL([BUILD_HEALTHCHECK_PLUGIN], [ test "$ac_cv_func_inotify_init" = "yes" ])

#
# Check for tcmalloc and jemalloc
TS_CHECK_JEMALLOC
TS_CHECK_TCMALLOC

#
# Check for libreadline/libedit
AX_LIB_READLINE

# On Darwin LuaJIT requires magic link options, otherwise it will crash in luaL_openlibs() at startup. See
# http://luajit.org/install.html.
case $host_os_def in
  darwin)
    TS_LUAJIT_LDFLAGS="-Wl,-pagezero_size,10000 -Wl,-image_base,100000000"
    ;;
esac

AC_SUBST(TS_LUAJIT_LDFLAGS)
AC_SUBST(LUA_LDFLAGS)

# We should be able to build http_load if epoll(2) is available.
AM_CONDITIONAL([BUILD_HTTP_LOAD], [test x"$ac_cv_func_epoll_ctl" = x"yes"])

# Check for spdylay library
if test "x${enable_spdy}" = "xyes"; then
  PKG_CHECK_MODULES([SPDYLAY],[libspdylay])
fi

# -----------------------------------------------------------------------------
# 5. CHECK FOR HEADER FILES

AC_CHECK_HEADERS([sys/types.h \
                  sys/uio.h \
                  sys/mman.h \
                  sys/epoll.h \
                  sys/event.h \
                  sys/param.h \
                  sys/pset.h \
                  sched.h \
                  pthread.h \
                  pthread_np.h \
                  machine/endian.h \
                  endian.h \
                  sys/sysinfo.h \
                  sys/systeminfo.h \
                  netinet/in.h \
                  netinet/in_systm.h \
                  netinet/tcp.h \
                  sys/ioctl.h \
                  sys/byteorder.h \
                  sys/sockio.h \
                  sys/prctl.h \
                  arpa/nameser.h \
                  arpa/nameser_compat.h \
                  execinfo.h \
                  netdb.h \
                  ctype.h \
                  siginfo.h \
                  malloc.h \
                  wait.h \
                  float.h \
                  libgen.h \
                  values.h \
                  alloca.h \
                  cpio.h \
                  stropts.h \
                  sys/param.h \
                  sys/sysmacros.h \
                  math.h \
                  stdint.h \
                  stdbool.h \
                  net/ppp_defs.h \
                  ifaddrs.h\
                  readline/readline.h \
                  editline/readline.h ])

AC_SUBST(sys_epollh)
AC_SUBST(sys_eventh)
AC_SUBST(machine_endianh)
AC_SUBST(endianh)
AC_SUBST(pthread_nph)
AC_SUBST(sys_paramh)
AC_SUBST(sys_cpuseth)
AC_SUBST(sys_pseth)
AC_SUBST(schedh)
AC_SUBST(netinet_inh)
AC_SUBST(netinet_in_systmh)
AC_SUBST(netinet_tcph)
AC_SUBST(sys_ioctlh)
AC_SUBST(sys_byteorderh)
AC_SUBST(sys_sockioh)
AC_SUBST(sys_sysctlh)
AC_SUBST(sys_sysinfoh)
AC_SUBST(sys_systeminfoh)
AC_SUBST(arpa_ineth)
AC_SUBST(arpa_nameserh)
AC_SUBST(arpa_nameser_compath)
AC_SUBST(execinfoh)
AC_SUBST(netdbh)
AC_SUBST(ctypeh)

AC_SUBST(siginfoh)
AC_SUBST(malloch)
AC_SUBST(waith)
AC_SUBST(floath)
AC_SUBST(libgenh)
AC_SUBST(valuesh)
AC_SUBST(allocah)
AC_SUBST(cpioh)
AC_SUBST(stroptsh)
AC_SUBST(sys_mounth)
AC_SUBST(sys_paramh)
AC_SUBST(sys_sysmacrosh)
AC_SUBST(mathh)
AC_SUBST(net_ppp_defsh)
AC_SUBST(ifaddrsh)
AC_SUBST(readline_readlineh)

AC_CHECK_HEADERS([sys/statfs.h sys/statvfs.h sys/disk.h sys/disklabel.h])
AC_CHECK_HEADERS([linux/hdreg.h linux/fs.h linux/major.h])

AC_CHECK_HEADERS([sys/sysctl.h], [], [],
                 [[#ifdef HAVE_SYS_PARAM_H
                    #include <sys/param.h>
                   #endif
                 ]])

AC_CHECK_HEADERS([sys/cpuset.h], [], [],
                 [[#ifdef HAVE_SYS_PARAM_H
                    #include <sys/param.h>
                   #endif
                 ]])

AC_CHECK_HEADERS([sys/mount.h], [], [],
                 [[#ifdef HAVE_SYS_PARAM_H
                    #include <sys/param.h>
                   #endif
                 ]])

AC_CHECK_HEADERS([arpa/inet.h], [], [],
                 [[#ifdef HAVE_SYS_TYPES_H
                    #include <sys/types.h>
                   #endif
                   #ifdef HAVE_NETINET_IN_H
                    #include <netinet/in.h>
                   #endif
                 ]])

AC_CHECK_HEADERS([netinet/ip.h], [], [],
                 [[#ifdef HAVE_SYS_TYPES_H
                    #include <sys/types.h>
                   #endif
                   #ifdef HAVE_NETINET_IN_H
                    #include <netinet/in.h>
                   #endif
                   #ifdef HAVE_NETINET_IN_SYSTM_H
                    #include <netinet/in_systm.h>
                   #endif
                 ]])

AC_CHECK_HEADERS([netinet/ip_icmp.h], [], [],
                 [[#ifdef HAVE_SYS_TYPES_H
                    #include <sys/types.h>
                   #endif
                   #ifdef HAVE_NETINET_IN_H
                    #include <netinet/in.h>
                   #endif
                   #ifdef HAVE_NETINET_IP_H
                    #include <netinet/ip.h>
                   #endif
                   #ifdef HAVE_NETINET_IN_SYSTM_H
                    #include <netinet/in_systm.h>
                   #endif
                 ]])

AC_SUBST(netinet_iph)
AC_SUBST(netinet_ip_icmph)

# Test for additional pthread interfaces.

# Darwin pthread_setname_np:
AC_MSG_CHECKING([for 1-parameter version of pthread_setname_np()])
AC_LINK_IFELSE([
    AC_LANG_PROGRAM([
#if HAVE_PTHREAD_H
#include <pthread.h>
#endif
#if PTHREAD_NP_H
#include <pthread_np.h>
#endif
      ], [
        pthread_setname_np("conftest");
    ])
  ], [
    AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_1, 1, [Whether the 1 parameter version of pthread_setname_np() is available])
    AC_MSG_RESULT([yes])
  ], [
    AC_MSG_RESULT([no])
])

# Linux pthread_setname_np:
AC_MSG_CHECKING([for 2-parameter version of pthread_setname_np()])
AC_LINK_IFELSE([
    AC_LANG_PROGRAM([
#if HAVE_PTHREAD_H
#include <pthread.h>
#endif
#if PTHREAD_NP_H
#include <pthread_np.h>
#endif
      ], [
        pthread_setname_np(pthread_self(), "conftest");
    ])
  ], [
    AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_2, 1, [Whether the 2 parameter version of pthread_setname_np() is available])
    AC_MSG_RESULT([yes])
  ], [
    AC_MSG_RESULT([no])
])

# BSD pthread_set_name_np:
AC_MSG_CHECKING([for 2-parameter version of pthread_set_name_np()])
AC_LINK_IFELSE([
    AC_LANG_PROGRAM([
#if HAVE_PTHREAD_H
#include <pthread.h>
#endif
#if PTHREAD_NP_H
#include <pthread_np.h>
#endif
      ], [
        pthread_set_name_np(pthread_self(), "conftest");
    ])
  ], [
    AC_DEFINE(HAVE_PTHREAD_SET_NAME_NP_2, 1, [Whether the 2 parameter version of pthread_set_name_np() is available])
    AC_MSG_RESULT([yes])
  ], [
    AC_MSG_RESULT([no])
])

# BSD-derived systems populate the socket length in the structure itself. It's
# redundant to check all of these, but hey, I need the typing practice.
AC_CHECK_MEMBER([struct sockaddr.sa_len], [], [], [#include <netinet/in.h>])
AC_CHECK_MEMBER([struct sockaddr_in.sin_len], [], [], [#include <netinet/in.h>])
AC_CHECK_MEMBER([struct sockaddr_in6.sin6_len], [], [], [#include <netinet/in.h>])

if test "x${ac_cv_member_struct_sockaddr_sa_len}" = xyes; then
    AC_DEFINE(HAVE_STRUCT_SOCKADDR_SA_LEN, 1,
            [Whether struct sockaddr_in has the sa_len member])
fi

if test "x${ac_cv_member_struct_sockaddr_in_sin_len}" = xyes ; then
AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN_SIN_LEN, 1,
            [Whether struct sockaddr_in has the sin_len member])
fi

if test "x${ac_cv_member_struct_sockaddr_in6_sin6_len}" = xyes; then
    AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN, 1,
            [Whether struct sockaddr_in6 has the sin6_len member])
fi

if test "x${with_profiler}" = "xyes"; then
AC_CHECK_HEADERS([google/profiler.h \
                  ], [], [])
fi

if test "x${enable_posix_cap}" != "xno"; then
  AC_CHECK_HEADERS([sys/capability.h],
    [],
    [AC_MSG_FAILURE([Found POSIX capabilities library but not the header sys/capability.h. POSIX capabilities are not a required feature, you can disable then with --disable-posix-cap])],
    []
  )
fi

# Check for high-resolution timestamps in struct stat
AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec])
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec])


#
# Configure sockopt value for TPROXY. Look at the enable flag.
# Value 'no' means user forced disable, don't check anything else.
#       'auto' means user didn't say, so silently enable/disable
#              based on success.
#       A numeric value means enable, don't check, use that value.
#       Anything else means user forced, fail if value not found
#       in header file.
# We can't just include linux/in.h because it's incompatible with
# netinet/in.h.
# Verify the file exists (is readable), scan for the value we need,
# if found export the value and enable use of the value.
#
ip_transparent=0
use_tproxy=0
tproxy_header=/usr/include/linux/in.h
tproxy_usage_enable="
    --enable-tproxy Enable the feature and validate."
tproxy_usage_default="
    --enable-tproxy=force Enable using default sockopt value, no validation."
tproxy_usage_numeric="
    --enable-tproxy=X where X is numeric
                      Enable, use X for sockopt value, no validation."
tproxy_usage_disable="
    --disable-tproxy Disable feature, no validation."
proxy_usage="$tproxy_usage_enable$tproxy_usage_default$tproxy_usage_numeric$tproxy_usage_disable"

AC_MSG_CHECKING([whether to enable transparent proxy])
AS_IF([test "x$enable_tproxy" != "xno"], [
  AS_IF([test "$use_posix_cap" -eq 0], [
    AS_IF([test "x$enable_tproxy" = xauto], [
      AC_MSG_RESULT([no])
    ],[
      AC_MSG_FAILURE([TPROXY feature requires POSIX capabilities.])
    ])
  ],[
    AC_MSG_CHECKING([for TPROXY sockopt IP_TRANSPARENT])
    case "$enable_tproxy" in
      [[0-9][0-9]*])
        ip_transparent=$enable_tproxy
        use_tproxy=1
        AC_MSG_RESULT([forced to $ip_transparent])
        ;;
      force)
        ip_transparent=19
        use_tproxy=1
        AC_MSG_RESULT([forced to $ip_transparent])
        ;;
      yes|auto)
        AS_IF([test -r $tproxy_header], [
          ip_transparent=`$AWK "/^#define[ \t]+IP_TRANSPARENT[ \t]+[0-9]+/{print \\$3}" $tproxy_header`
          AS_IF([test "x$ip_transparent" != "x"], [
            use_tproxy=1
            AC_MSG_RESULT([set to $ip_transparent])
          ],[
            ip_transparent=0
            AS_IF([test "x$enable_tproxy" = xauto], [
             AC_MSG_RESULT([no])
            ],[
              AC_MSG_RESULT([failed])
              AC_MSG_FAILURE([tproxy feature enabled but the sockopt value was not found in $tproxy_header. Try one of$tproxy_usage_default$tproxy_usage_numeric$tproxy_usage_disable])
            ])
          ])
        ],[
          AS_IF([test "x$enable_tproxy" = xauto], [
            AC_MSG_RESULT([no])
          ],[
            AC_MSG_RESULT([failed])
            AC_MSG_FAILURE([tproxy feature enabled but the header file $tproxy_header was not readable. Try one of$tproxy_usage_default$tproxy_usage_numeric$tproxy_usage_disable])
          ])
        ])
        ;;
      *)
        AC_MSG_RESULT([failed])
        AC_MSG_FAILURE([Invalid argument to feature tproxy.$tproxy_usage])
        ;;
      esac
  ])
])

AC_SUBST(use_tproxy)
AC_SUBST(ip_transparent)

AC_MSG_CHECKING([for SO_MARK])
AC_TRY_COMPILE([
#include <sys/socket.h>
], [
if( SO_MARK > 0) return 0;
else return 1;
], [has_so_mark=1]
msg=yes, [
has_so_mark=0
msg=no ] )

AC_MSG_RESULT([$msg])
AC_SUBST(has_so_mark)

AC_MSG_CHECKING([for IP_TOS])
AC_TRY_COMPILE([
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
],[
if( IP_TOS > 0) return 0;
else return 1;
], [has_ip_tos=1]
msg=yes, [
has_ip_tos=0
msg=no ] )

AC_MSG_RESULT([$msg])
AC_SUBST(has_ip_tos)

TS_CHECK_LOOPBACK_IFACE
TS_CHECK_GETHOSTBYNAME_R_STYLE
TS_CHECK_MACRO_IN6_IS_ADDR_UNSPECIFIED

AC_CHECK_TYPE([struct tcp_info],
  [AC_DEFINE(HAVE_STRUCT_TCP_INFO, 1, [whether struct tcp_info is available])],
  [],
  [[
   #include <netinet/in.h>
   #include <netinet/tcp.h>
  ]]
)

# See if we can build the remap_stats plugin
AS_IF([test "x$enable_experimental_plugins" = xyes],
  [
    AC_CHECK_HEADERS([search.h])
    AS_IF([test "x$ac_cv_header_search_h" = "xyes"],
      [
        AC_CHECK_TYPE([struct hsearch_data],[],[],[[#include <search.h>]])
        AC_CHECK_FUNCS([hcreate_r hsearch_r])
      ])
  ])
AM_CONDITIONAL([BUILD_REMAP_STATS_PLUGIN],
  [ test "x$enable_experimental_plugins" = "xyes" -a "x$ac_cv_header_search_h" = "xyes" -a "x$ac_cv_type_struct_hsearch_data" = "xyes" -a "x$ac_cv_func_hcreate_r" = "xyes" -a "x$ac_cv_func_hsearch_r" = "xyes" ])

AM_CONDITIONAL([BUILD_COLLAPSED_CONNECTION_PLUGIN],
  [ test "x$enable_experimental_plugins" = "xyes" -a "x${enable_collapsed_connection_plugin}" != "xno" ])

#
# use modular IOCORE
#
iocore_include_dirs="-I\$(top_srcdir)/iocore/eventsystem \
-I\$(top_srcdir)/iocore/net \
-I\$(top_srcdir)/iocore/aio \
-I\$(top_srcdir)/iocore/hostdb \
-I\$(top_srcdir)/iocore/cache \
-I\$(top_srcdir)/iocore/cluster \
-I\$(top_srcdir)/iocore/utils \
-I\$(top_srcdir)/iocore/dns"

# Testing Framework suffix generation hack
TFW_PACKAGE_SUFFIX=$os_type

AC_SUBST([API_DEFS])
AC_SUBST([CC])
AC_SUBST([CFLAGS])
AC_SUBST([CXX])
AC_SUBST([CXXFLAGS])
AC_SUBST([EXPAT_LDFLAGS])
AC_SUBST([EXTRA_CC_LDFLAGS])
AC_SUBST([EXTRA_CXX_LDFLAGS])
AC_SUBST([LIBTOOL_LINK_FLAGS])
AC_SUBST([iocore_include_dirs])
AC_SUBST([LDFLAGS])
AC_SUBST([SHARED_CFLAGS])
AC_SUBST([SHARED_CXXFLAGS])
AC_SUBST([SHARED_CXXLINKFLAGS])
AC_SUBST([SHARED_LDFLAGS])
AC_SUBST([TFW_PACKAGE_SUFFIX])

# -----------------------------------------------------------------------------
# 6. OUTPUT FILES

AC_CONFIG_FILES([
  Makefile
  cmd/Makefile
  cmd/traffic_cop/Makefile
  cmd/traffic_layout/Makefile
  cmd/traffic_line/Makefile
  cmd/traffic_manager/Makefile
  cmd/traffic_top/Makefile
  cmd/traffic_via/Makefile
  doc/Makefile
  example/Makefile
  iocore/Makefile
  iocore/aio/Makefile
  iocore/cache/Makefile
  iocore/cluster/Makefile
  iocore/dns/Makefile
  iocore/eventsystem/Makefile
  iocore/hostdb/Makefile
  iocore/net/Makefile
  iocore/utils/Makefile
  lib/Makefile
  lib/perl/Makefile
  lib/perl/lib/Apache/TS.pm
  lib/records/Makefile
  lib/ts/Makefile
  lib/ts/apidefs.h
  lib/ts/ink_config.h
  lib/tsconfig/Makefile
  lib/wccp/Makefile
  mgmt/Makefile
  mgmt/api/Makefile
  mgmt/api/include/Makefile
  mgmt/cluster/Makefile
  mgmt/utils/Makefile
  mgmt/web2/Makefile
  plugins/Makefile
  plugins/cacheurl/Makefile
  plugins/conf_remap/Makefile
  plugins/gzip/Makefile
  plugins/header_rewrite/Makefile
  plugins/libloader/Makefile
  plugins/regex_remap/Makefile
  plugins/stats_over_http/Makefile
  plugins/tcpinfo/Makefile
  proxy/Makefile
  proxy/api/ts/Makefile
  proxy/config/Makefile
  proxy/config/body_factory/Makefile
  proxy/config/body_factory/default/Makefile
  proxy/config/records.config.default
  proxy/config/storage.config.default
  proxy/congest/Makefile
  proxy/hdrs/Makefile
  proxy/http/Makefile
  proxy/http/remap/Makefile
  proxy/http2/Makefile
  proxy/logging/Makefile
  proxy/shared/Makefile
  proxy/spdy/Makefile
  rc/Makefile
  rc/trafficserver
  rc/trafficserver.conf
  rc/trafficserver.service
  rc/trafficserver.xml
  tools/Makefile
  tools/tsxs
])

AC_CHECK_HEADERS([mysql/mysql.h], [has_mysql=1],[has_mysql=0])
AC_CHECK_LIB([mysqlclient],[mysql_info],[AC_SUBST([LIB_MYSQLCLIENT],["-lmysqlclient"])],[has_mysql=0])
AC_SUBST(has_mysql)
AM_CONDITIONAL([HAS_MYSQL], [ test "x${has_mysql}" = "x1" ])

AS_IF([test "x$enable_experimental_plugins" = xyes], [  
  AC_CONFIG_FILES([
    plugins/experimental/mysql_remap/Makefile
    plugins/experimental/Makefile
    plugins/experimental/authproxy/Makefile
    plugins/experimental/background_fetch/Makefile
    plugins/experimental/balancer/Makefile
    plugins/experimental/buffer_upload/Makefile
    plugins/experimental/channel_stats/Makefile
    plugins/experimental/collapsed_connection/Makefile
    plugins/experimental/custom_redirect/Makefile
    plugins/experimental/epic/Makefile
    plugins/experimental/escalate/Makefile
    plugins/experimental/esi/Makefile
    plugins/experimental/geoip_acl/Makefile
    plugins/experimental/healthchecks/Makefile
    plugins/experimental/hipes/Makefile
    plugins/experimental/metalink/Makefile
    plugins/experimental/regex_revalidate/Makefile
    plugins/experimental/remap_stats/Makefile
    plugins/experimental/s3_auth/Makefile
    plugins/experimental/sslheaders/Makefile
    plugins/experimental/ssl_cert_loader/Makefile
    plugins/experimental/stale_while_revalidate/Makefile
    plugins/experimental/ts_lua/Makefile
    plugins/experimental/url_sig/Makefile
    plugins/experimental/xdebug/Makefile
])])

AS_IF([test "x$enable_cppapi" = xyes], [
  AC_CONFIG_FILES([
  lib/atscppapi/Makefile
  lib/atscppapi/examples/Makefile
  lib/atscppapi/examples/async_http_fetch/Makefile
  lib/atscppapi/examples/async_timer/Makefile
  lib/atscppapi/examples/clientredirect/Makefile
  lib/atscppapi/examples/clientrequest/Makefile
  lib/atscppapi/examples/customresponse/Makefile
  lib/atscppapi/examples/boom/Makefile
  lib/atscppapi/examples/globalhook/Makefile
  lib/atscppapi/examples/gzip_transformation/Makefile
  lib/atscppapi/examples/helloworld/Makefile
  lib/atscppapi/examples/intercept/Makefile
  lib/atscppapi/examples/internal_transaction_handling/Makefile
  lib/atscppapi/examples/logger_example/Makefile
  lib/atscppapi/examples/multiple_transaction_hooks/Makefile
  lib/atscppapi/examples/null_transformation_plugin/Makefile
  lib/atscppapi/examples/post_buffer/Makefile
  lib/atscppapi/examples/remap_plugin/Makefile
  lib/atscppapi/examples/serverresponse/Makefile
  lib/atscppapi/examples/stat_example/Makefile
  lib/atscppapi/examples/timeout_example/Makefile
  lib/atscppapi/examples/transactionhook/Makefile
  lib/atscppapi/examples/async_http_fetch_streaming/Makefile
  lib/atscppapi/src/Makefile
])])

AC_CONFIG_SUBDIRS([lib/ck])

# -----------------------------------------------------------------------------
# 7. autoheader TEMPLATES

AC_OUTPUT

AC_MSG_NOTICE([Build option summary:
    CC:                 $CC
    CXX:                $CXX
    CPP:                $CPP
    CFLAGS:             $CFLAGS
    SHARED_CFLAGS:      $SHARED_CFLAGS
    CXXFLAGS:           $CXXFLAGS
    SHARED_CXXFLAGS:    $SHARED_CXXFLAGS
    SHARED_CXXLINKFLAGS:$SHARED_LINKCXXFLAGS
    CPPFLAGS:           $CPPFLAGS
    LDFLAGS:            $LDFLAGS
    SHARED_LDFLAGS:     $SHARED_LDFLAGS
    EXTRA_CC_LDFLAGS:   $EXTRA_CC_LDFLAGS
    EXTRA_CXX_LDFLAGS:  $EXTRA_CXX_LDFLAGS
    LIBTOOL_LINK_FLAGS: $LIBTOOL_LINK_FLAGS
    API_DEFS:           $API_DEFS

])
